package com.zyg.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zyg.dao.StudentMapper;
import com.zyg.pojo.Student;
import com.zyg.service.StudentService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service("studentService")
public class StudentServiceImpl extends ServiceImpl<StudentMapper,Student> implements StudentService {
    @Override
    public List<Object[]> getGradeDistribution() {
        // 使用自定义SQL查询来关联班级和年级表
        return baseMapper.getGradeDistribution().stream()
                .map(map -> new Object[]{map.get("grade_name"), map.get("count")})
                .collect(Collectors.toList());
    }


    @Override
    public List<Object[]> getMajorDistribution() {
        // 使用自定义SQL查询来获取专业分布数据
        return baseMapper.getMajorDistribution().stream()
                .map(map -> new Object[]{map.get("major"), map.get("count")})
                .collect(Collectors.toList());
    }

    @Override
    public List<Object[]> getHotelDistribution() {
        // 使用自定义SQL查询来获取宿舍分布数据
        return baseMapper.getHotelDistribution().stream()
                .map(map -> new Object[]{map.get("hotelId"), map.get("count")})
                .collect(Collectors.toList());
    }

    @Override
    public List<Object[]> getAgeDistribution() {
        // 使用自定义SQL查询来获取年龄分布数据
        return baseMapper.getAgeDistribution().stream()
                .map(map -> new Object[]{map.get("age"), map.get("count")})
                .collect(Collectors.toList());
    }


}
